const { DataTypes } = require("sequelize");
const sequelize = require("./db");

//define(表名,定义列)
//studnet name age gender
const Students = sequelize.define(
  "student",
  {
    name: {
      type: DataTypes.STRING,
      allowNull: false,
      //名字必须是2到4字
      validate: {
        //匹配一个正则 必须是2到4个字符之间
        is: /^[\u4e00-\u9fa5]{2,4}$/,
      },
    },
    age: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    //0>male,1>female,2>other
    gender: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
    },
  },
  {
    paranoid: true, //软删除
  }
);
module.exports = Students;
